<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .select {
            width: 100px;
            margin: 30px;
            text-align: center;
        }

        p {
            line-height: 40px;
            border: 1px solid #000;
        }

        ul {
            display: none;
        }

        li {
            line-height: 40px;
            border: 1px solid #000;
        }
    </style>
</head>

<body>

    <div class="select">
        <p>请选择</p>
        <ul>
            <li>吃饭</li>
            <li>睡觉</li>
            <li>打代码</li>
            <li>打豆豆</li>
        </ul>
    </div>

    <script>

        // p 
        // li 
        // document

        // 共同的祖先元素  document

        var oUl = document.querySelector('ul');




        document.onclick = function (e) {
            e = e || event;
            var target = e.target || e.srcElement;

            // p
            if (target.tagName === 'P') {
                // this  替换成  target
                target.nextElementSibling.style.display = 'block';
                return;    // 必须写return 
            }

            // li
            if (target.tagName === 'LI') {
                target.parentElement.previousElementSibling.innerHTML = target.innerHTML;
                target.parentElement.style.display = 'none';
                return;
            }

            oUl.style.display = 'none';
        }

    </script>

</body>

</html>